package com.cy3;
/*
用于测试hashmap嵌套arraylist集合
 */
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapIncludeArrayList {
    public static void main(String[] args) {
        HashMap<String, ArrayList<String>> hm = new HashMap<>();
        ArrayList<String> sgyy = new ArrayList<>();
        sgyy.add("貂蝉");
        sgyy.add("小乔");
        hm.put("三国演义", sgyy);
        ArrayList<String> xyj = new ArrayList<>();
        xyj.add("蜘蛛精");
        xyj.add("女儿国国王");
        hm.put("西游记", xyj);
        ArrayList<String> shz = new ArrayList<>();
        shz.add("林冲");
        shz.add("武松");
        hm.put("水浒传", shz);
        Set<String> strings = hm.keySet();
        for (String string : strings) {
            System.out.println(string);
            ArrayList<String> strings1 = hm.get(string);
            for (String s : strings1) {
                System.out.println("\t" + s);
            }
        }
        System.out.println("---------------");
        Set<Map.Entry<String, ArrayList<String>>> entries = hm.entrySet();
        for (Map.Entry<String, ArrayList<String>> entry : entries) {
            System.out.println(entry.getKey());
            ArrayList<String> value = entry.getValue();
            for (String s : value) {
                System.out.println("\t"+s);
            }
        }
    }
}
